package com.example.cpoopc.helloretrofit.bean;

import android.text.SpannableStringBuilder;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;

/**
 * 帖子信息
 * 
 * <br>
 * Created 2014-8-21 上午10:40:54
 * 
 * @version
 * @author chenpeng
 * 
 * @see
 */
public class PostEntity implements Serializable {
	/**
     * 
     */
	private static final long serialVersionUID = 3493304015570781410L;
	public static final int C_TAG_JAY = 1;
	public static final int C_TAG_PICKED = 1;
	public static final int C_PRAISE_DONE = 1;
	public static final int C_PRAISE_UNDONE = 0;

	public static final SpannableStringBuilder PICKED_SPAN = new SpannableStringBuilder("picked");
	
	public String category;// "text","audio","image"
	public String location;// 发帖地点
	public String birthplace;//
	// userinfo
	public UserInfo user;// 发帖人信息
	public long distance;// 发帖人距离 TODO 服务端暂时缺少该数据
	public long tid;// 帖子ID
	public long root_tid;// 父贴ID

	public long post_time;// 发布时间
	public String title; // 帖子标题
	public String article;// 正文内容,(语音，微博，图片)
	public String content;// 正文内容,(语音，微博，图片)
	public SpannableStringBuilder contentSpan;
	public boolean hasLayout;// 用于文字限制行数时的截取
	public boolean hasMore;// 是否显示不完全
	public boolean isRead = false; // 帖子是否已读
	public boolean showSelect = false;// 帖子被选中状态（默认不被选中）
	public boolean isSendFail = false;// 发送失败
	public boolean isSending = false;// 发送失败

	// images
//	public ImgInfoList images;// 图片内容
//	public ArrayList<ImgInfo> images;// 图片内容
    public ImgInfoList images;
	/**
	 * 发送失败时的本地图片
	 */
	public ArrayList<String> localImagePath;
	// audio
//	public AudioInfo audio;// 微博语音内容
	public ArrayList<AudioInfo> audio;// 微博语音内容

	public long reply_num;// "评论数"
	public long praise_num;// "点赞数"
	public int praise_done;// "是否已赞"
	public long c_num;// "踩数"
	public int c_done;// "是否已踩"
	public int stamp;// 1/0 标签(Jay) 暂无
	public int picked;// 1/0 是否加精 暂无

	// jay
	public JayInfo jay_info;// 杰伦参与内容

	public ArrayList<MentionInfo> mentions;
	
	public long relate_id;// 跳转界面关联的id，可选  category为行程（schedule）、电影（film）、活动（activity）时必填，跳转用的tid/fid
	
	public JSONObject toJsonObject() throws JSONException {
		JSONObject jb = new JSONObject();
		jb.put("category", category);
		jb.put("location", location);
		jb.put("birthplace", birthplace);
		if (user != null) {
			jb.put("user", user.toJsonObject());
		}
		jb.put("distance", distance);
		jb.put("id", tid);
		jb.put("root_tid", root_tid);
		jb.put("post_time", post_time);
		jb.put("distance", distance);
		if (title != null) {
			jb.put("title", title);
		}
		jb.put("article", article);
		jb.put("content", content);
//		if (images != null) {
//			jb.put("images", images.toJsonArray());
//		}

		if (audio != null && audio.size()>0) {
			jb.put("audio", audio.get(0).toJsonArray());
		}

		jb.put("reply_num", reply_num);
		jb.put("praise_num", praise_num);
		jb.put("praise_done", praise_done);
		jb.put("c_num", c_num);
		jb.put("c_done", c_done);
		jb.put("stamp", stamp);
		jb.put("picked", picked);
		if (jay_info != null) {
			jb.put("jay_info", jay_info.toJsonObject());
		}
		if (mentions != null) {
			JSONArray ja = new JSONArray();
			for (int i = 0; i < mentions.size(); i++) {
				ja.put(mentions.get(i).toJsonObject());
			}
			jb.put("mentions", ja);
		}
//		jb.put("hasLayout", hasLayout);
		jb.put("hasMore", hasMore);
		jb.put("isRead", isRead);
		jb.put("relate_id", relate_id);
		return jb;
	}
//	public static void parseString(PostEntity postEntity,boolean isLimit, boolean hidePickedTag, boolean appendTitle, boolean ignoreLineBreak){
//	    if(postEntity == null)return;
//	    MyTextView.parseString2Span(postEntity,
//                isLimit, MyTextView.DEFAULT_AT_COLOR, hidePickedTag, appendTitle, ignoreLineBreak);
//	}
//
//	public boolean isShowSelect() {
//		return showSelect;
//	}
//
//	public void setShowSelect(boolean showSelect) {
//		this.showSelect = showSelect;
//	}


}
